﻿

using Microsoft.Playwright;
using Newtonsoft.Json.Linq;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OnlineStore
{
    public abstract class Player
    {
        public Player(PlayerTask playerTask, ExecuteStatus status)
        {
            this.playerTask = playerTask;
            this.MyStatus = status;
        }

        abstract public Task Execute(IBrowser browser);

        /// <summary>
        /// 通过指定关键字获取值
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns>返回对应的字符串值</returns>
        public string GetPath(string key)
        {
            return this.PathConfig[key].ToString();
        }


        /// <summary>
        /// 任务管理器
        /// </summary>
        private PlayerTask playerTask;

        /// <summary>
        /// 执行状态
        /// </summary>
        public ExecuteStatus MyStatus { get; set; }

        /// <summary>
        /// 一个输出服务器返回信息的方法
        /// </summary>
        public Action<string> DetailedAction { get; set; }

        /// <summary>
        /// 一个输出任务进度的方法
        /// </summary>
        public Action<int ,int> ProgressAction { get; set; }


        /// <summary>
        /// 已经适用的标题列表
        /// </summary>
        private List<string> usedTitles = new List<string>();

        /// <summary>
        /// 已使用宝贝标题列表
        /// </summary>
        public List<string> UsedTitles { get => usedTitles; set => usedTitles = value; }

        /// <summary>
        /// 获取浏览器导航
        /// </summary>
        public JObject PathConfig { get => playerTask.PathConfig; }


        /// <summary>
        /// 获取 playwrigth 初始配置
        /// </summary>
        public JObject PwSettingConfig { get => playerTask.PwSettingConfig; }

        /// <summary>
        /// 获取网店类型
        /// </summary>
        public string Type { get => playerTask.Type; }

        /// <summary>
        /// 账号
        /// </summary>
        public string User { get => playerTask.User; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get => playerTask.Password; }

        /// <summary>
        /// 账号ID
        /// </summary>
        public string Id { get => playerTask.Id; }

        /// <summary>
        /// 模板宝贝ID
        /// </summary>
        public string ModelBaby { get => playerTask.ModelBaby; }

        /// <summary>
        /// 标题文件
        /// </summary>
        public string TitlePath { get => playerTask.TitlePath; }

        /// <summary>
        /// 上版LOG文件
        /// </summary>
        public string LogPath { get => playerTask.LogPath; }

        /// <summary>
        /// 发布延迟
        /// </summary>
        public int Delay { get => playerTask.Delay; }

        /// <summary>
        /// 发布数量
        /// </summary>
        public int Count { get => playerTask.Count; }

        /// <summary>
        /// 登录记录文件名
        /// </summary>
        public string Cookie { get => playerTask.Cookie;}

        /// <summary>
        /// 宝贝标题列表
        /// </summary>
        public List<string> TitleList { get => playerTask.TitleList; }

        /// <summary>
        /// 车型图片列表
        /// </summary>
        public List<string> PicList { get => playerTask.PicList; }

        /// <summary>
        /// 车型图片：车型标题，导航
        /// </summary>
        public Dictionary<string, string> CarMap { get => playerTask.CarMap; }


        /// <summary>
        /// 网店发布间隔时间
        /// </summary>
        public int TimeInterval { get => playerTask.TimeInterval; }

        /// <summary>
        /// 网店发布间隔时间
        /// </summary>
        public int Save { get => playerTask.Save; }

        /// <summary>
        /// 获取 标题输入延迟
        /// </summary>
        public int TitleDelay { get => playerTask.TitleDelay; }

        /// <summary>
        /// 获取标题文件目录
        /// </summary>
        public string RootPath { get => playerTask.RootPath; }

        /// <summary>
        /// 用户名别名
        /// </summary>
        public string OtherName { get => playerTask.OtherName; }

        /// <summary>
        /// 异常截图目录
        /// </summary>
        public string ErrPicPath { get => playerTask.ErrPicPath; }

        /// <summary>
        /// 异常截图提醒文件地址
        /// </summary>
        public string ErrTxtPath { get => playerTask.ErrTxtPath; }

    }
}
